package com.ruoyi.yuyuan.Utils;

import org.springframework.core.io.ClassPathResource;
import org.springframework.data.redis.core.script.DefaultRedisScript;
//

/**
 * Redis固定常量(前缀)
 */
public class RedisConstants {
    /**
     * 登录用户token
     */
    public static final String LOGIN_USER_TOKEN_KEY = "login:user:token:";
    /**
     * 发帖TTL
     */
    public static final String BLOG_CREATE_STRING_TTL = "blog:publish:ttl:";
    /**
     * 验证码登录
     */
    public static final String LOGIN_CODE = "login:code:";
    /**
     * 贴子点赞
     */
    public static final String BLOG_LIKE_KEY = "blog:liked:";
    /**
     * 评论点赞
     */
    public static final String COMMENT_LIKE_KEY = "comment:liked:";
    /**
     * 解决缓存击穿TTL
     */
    public static final String BLOG_TTL_KEY="blog:";
    /**
     * 加入约球lua脚本
     */
    public static final DefaultRedisScript<Long> JOIN_SCRIPT = new DefaultRedisScript<>();
    static {
        JOIN_SCRIPT.setLocation(new ClassPathResource("join.lua"));
        JOIN_SCRIPT.setResultType(Long.class);
    }

    /**
     * 评论发布TTL
     */
    public static final String COMMENT_CREATE_STRING_TTL = "comment:publish:ttl:";
    /**
     * 发帖加锁
     */
    public static final String BLOG_PUBLISH_LOCK = "blog:publish:lock:";
    /**
     * 更新贴加锁
     */
    public static final String BLOG_UPDATE_LOCK = "blog:update:lock:";
    /**
     * 关注
     */
    public static final String FOLLOWS_KEY = "follows:";
    /**
     * 关注加锁
     */
    public static final String FOLLOWS_LOCK = "follows:lock:";
    /**
     * 验证openId与Id绑定性
     */
    public static final String OPENID_ID_KEY = "user:openId:";
    /**
     * 博客评论数量
     */
    public static final String BLOG_COMMENT_NUM = "blog:commentsNum:";
    /**
     * 博客点击量
     */
    public static final String BLOG_CLICK_KEY = "blog:view:";
    /**
     * 图片暂存Set
     */
    public static final String UPLOAD_FILE_SET = "upload:file";
    /**
     * 图片确认Set
     */
    public static final String UPLOAD_FILE_CONFIRM_SET = "upload:confirm";
    /**
     * 图片确认String
     */
    public static final String UPLOAD_FILE_CONFIRM_STRING = "upload:confirmString:";

    /**
     * 帖子得分
     */
    public static String getPostScoreKey(){
        return "blog:score:";
    }
}
